﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Selenium;
using ThoughtWorks.Selenium.UnitTests;
using SeleniumTestProject.Tests.Core;
using SeleniumTestProject.Tests.EntityStore;
using System.Configuration;
using NLog;

namespace SeleniumTestProject
{
    [TestFixture]
    public class FlightRoundTrip
    {
        private PaymentCardDetails pcd=new PaymentCardDetails();
        private UserAddressInfo uai=new UserAddressInfo();
        private SearchParametres sp=new SearchParametres();
        private LoginParameters lp = new LoginParameters();
        private POSSelector selector = new POSSelector();
        Core core;
        private static Logger logger = LogManager.GetLogger("FlightRoundTrip");

        [TestFixtureSetUp]
        public void SetupTest()
        {
            pcd.UserName = "Tessan";
            pcd.UserSecondName = "MacIntegration";
            pcd.UserSelectedCardType = "";
            pcd.UserCardNumber = "1234999987654321";
            pcd.ExpirationDateMonth = "05-May";
            pcd.ExpirationDateYear = "2015";
            pcd.UserSelectedCardType = "value=0";
            pcd.CVV = "555";
            
            uai.Area = "1";
            uai.City = "Bellevue";
            uai.Country = "USA";
            uai.Ext = "425";
            uai.Phone = "6797200";
            uai.State = "WA";
            uai.Street = "AVE 138th SE"; 
            uai.ZipCode = "98005";

            sp.CityFrom = "LHR";
            sp.CityTo="JFK";
            sp.DateFrom = ConfigurationSettings.AppSettings["Settings_depDate"].ToString();
            sp.DateReturn = ConfigurationSettings.AppSettings["Settings_retDate"].ToString();

            lp.LoginName = "intbook@expedia.com";
            lp.LoginPassword = "control";             
            core=new Core(50000,pcd,uai,sp,lp);
        }

        [Test]
        public void FlightRoundTrip_Test()
        {
            logger.Info("New test started!");
            core.Step01();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step01")),"We are not on the expected page. Page with flight search results is absent. Found "+core.Selenium.GetTitle());
            logger.Debug("Step01 completed");
            //select first flight from search results            
            core.Step02();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step02")), "We are not on the expected page. Page with returning flight result is absent. Found " + core.Selenium.GetTitle());
            logger.Debug("Step02 completed");
            //select first returning flight from search results            
            core.Step03();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step03")), "We are not on the expected page. Agreement page is absent.");
            logger.Debug("Step03 completed");
            //check argeement option and go on
            core.Step04();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step04")), "We are not on the expected page. Page with user details filling is absent. Found " + core.Selenium.GetTitle());
            logger.Debug("Step04 completed");
            //choosing person and filling his details
            core.Step05();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step05")), "We are not on the expected page. Payment page is absent. Found " + core.Selenium.GetTitle());//BE false-error message
            logger.Debug("Step05 completed");
            //filling payment details
            core.Step06();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step06")), "We are not on the expected page. Payment page is absent. Found " + core.Selenium.GetTitle());//BE false-error message
            logger.Debug("Step06 completed");
            //BE payment page
            core.Step07_BE();
            Assert.IsTrue(core.Selenium.IsTextPresent(selector.GetSteppedPageTextByKey("Step07")), "We are not on the expected page. Post-Payment page is absent. Found " + core.Selenium.GetTitle());
            logger.Debug("Step07 completed");
            logger.Warn("Test successfully completed!");
        }

        [TestFixtureTearDown]
        public void Finishing()
        {
            //closing selenium object
            core.CloseSeleniumObject();
        }
    }
}
